package com.jdaw.datastructure.sort;

public class BubbleSort {
    public static void main(String[] args) {
        int[] arr={3,9,-1,10,20};
        for(int j=0;j<arr.length-1;j++) {
            boolean flag=false;
            for (int i = 0; i < arr.length - 1-j; i++) {
                if (arr[i] > arr[i + 1]) {
                    int temp;
                    flag=true;
                    temp = arr[i];
                    arr[i] = arr[i + 1];
                    arr[i + 1] = temp;
                }
            }
            if(flag=false){
                break;
            }
        }
        for(int n=0;n<arr.length;n++){
            System.out.println(arr[n]);
        }
    }
}
